package com.ego.service.impl;

import com.ego.dubbo.service.ManageDubboService;
import com.ego.pojo.Manager;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements UserDetailsService {

    @DubboReference
    private ManageDubboService manageDubboService;

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        Manager manager = manageDubboService.selectManagerByUsername(s);
        if (manager == null) {
            throw new UsernameNotFoundException("用户名不存在~");
        }

        return new User(manager.getUsername(), manager.getPassword(), AuthorityUtils.commaSeparatedStringToAuthorityList(""));
    }

}
